package com.buddy.learn.spring.framework.aop.aspect;

import com.buddy.learn.spring.framework.aop.intercept.BMethodInterceptor;
import com.buddy.learn.spring.framework.aop.intercept.BMethodInvocation;

import java.lang.reflect.Method;

public class BAfterThrowingAdviceInterceptor extends BAbstractAspectAdvice implements BMethodInterceptor {

    private String throwName;


    public BAfterThrowingAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(BMethodInvocation mi) throws Throwable {
        try {
            return mi.proceed();
        } catch (Exception e) {
            invokeAdviceMethod(mi, null, e.getCause());
            throw e;
        }
    }

    public String getThrowName() {
        return throwName;
    }

    public void setThrowName(String throwName) {
        this.throwName = throwName;
    }
}
